{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "像素基本知识\n",
    "1 像素\n",
    "2 RGB三原色\n",
    "3 颜色深度 8bit 0-255\n",
    "4 图片宽度w和高度h 640*480\n",
    "5 图像大小计算：1.14M = 720*547*3*8 bit / 8 (转化B)/1000（转化为MB）\n",
    "6 png相对于RGB属性还多了alpha属性，该属性值表示透明度\n",
    "7 RGB bgr即顺序颠倒\n",
    "8 每个颜色分量称之为颜色通道\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "img= cv2.imread('image0.jpg',1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "39 46 49\n"
     ]
    }
   ],
   "source": [
    "# 通过坐标系读取像素值,opencv的颜色顺序为bgr\n",
    "(b,g,r) = img[100,100]\n",
    "print(b,g,r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 像素的写入 ，绘制一条直线 10 100 ----- 110 100 从第10行第100列开始到第110行第100列\n",
    "for i in range(1,100):\n",
    "    img[10 + i,100] = (255,0,0)\n",
    "cv2.imshow('image',img)\n",
    "# 参数单位为ms代表程序暂停时间，为0时代表一直暂停\n",
    "cv2.waitKey(0) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
